package com.yipei.business.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yipei.business.domain.MlInvestmentProducts;
import com.yipei.business.domain.MlInvestmentType;
import com.yipei.business.service.IMlInvestmentProductsService;
import com.yipei.business.service.IMlInvestmentTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.enums.BusinessType;
import com.yipei.business.domain.MlInvestmentProductOrder;
import com.yipei.business.service.IMlInvestmentProductOrderService;
import com.yipei.common.utils.poi.ExcelUtil;
import com.yipei.common.core.page.TableDataInfo;

/**
 * 投资产品订单Controller
 *
 * @author yipei
 * @date 2025-07-14
 */
@RestController
@RequestMapping("/business/investorder")
public class MlInvestmentProductOrderController extends BaseController
{
    @Autowired
    private IMlInvestmentProductOrderService mlInvestmentProductOrderService;
    @Autowired
    private IMlInvestmentProductsService iMlInvestmentProductsService;
    /**
     * 查询投资产品订单列表
     */
    @PreAuthorize("@ss.hasPermi('business:investorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(MlInvestmentProductOrder mlInvestmentProductOrder)
    {
        startPage();
        List<MlInvestmentProductOrder> list = mlInvestmentProductOrderService.selectMlInvestmentProductOrderList(mlInvestmentProductOrder);
        return getDataTable(list);
    }

    /**
     * 导出投资产品订单列表
     */
    @PreAuthorize("@ss.hasPermi('business:investorder:export')")
    @Log(title = "投资产品订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MlInvestmentProductOrder mlInvestmentProductOrder)
    {
        List<MlInvestmentProductOrder> list = mlInvestmentProductOrderService.selectMlInvestmentProductOrderList(mlInvestmentProductOrder);
        ExcelUtil<MlInvestmentProductOrder> util = new ExcelUtil<MlInvestmentProductOrder>(MlInvestmentProductOrder.class);
        util.exportExcel(response, list, "投资产品订单数据");
    }

    /**
     * 获取投资产品订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:investorder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mlInvestmentProductOrderService.selectMlInvestmentProductOrderById(id));
    }

    /**
     * 新增投资产品订单
     */
    @PreAuthorize("@ss.hasPermi('business:investorder:add')")
    @Log(title = "投资产品订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MlInvestmentProductOrder mlInvestmentProductOrder) throws Exception {
        return toAjax(mlInvestmentProductOrderService.insertMlInvestmentProductOrder(mlInvestmentProductOrder));
    }

    /**
     * 修改投资产品订单
     */
    @PreAuthorize("@ss.hasPermi('business:investorder:edit')")
    @Log(title = "投资产品订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MlInvestmentProductOrder mlInvestmentProductOrder)
    {
        return toAjax(mlInvestmentProductOrderService.updateMlInvestmentProductOrder(mlInvestmentProductOrder));
    }

    /**
     * 删除投资产品订单
     */
    @PreAuthorize("@ss.hasPermi('business:investorder:remove')")
    @Log(title = "投资产品订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mlInvestmentProductOrderService.deleteMlInvestmentProductOrderByIds(ids));
    }

    @ApiOperation("获取基金分类名称")
    @GetMapping("/searchProducts")
    public AjaxResult searchClassificationName() throws IOException {
        List<MlInvestmentProducts> list = iMlInvestmentProductsService.lambdaQuery().list(); // 自定义方法
        // 转成 { label, value } 格式供前端
        return AjaxResult.success(list);
    }
}
